fitted <- as.numeric(model.4.i.pop$model[[1]] - model.4.i.pop$residuals) 
countryNames <- epr.final$countryname[as.numeric(rownames(model.4.i.pop$model))]
outcome <- as.numeric(model.4.i.pop$model$legippop)
conference <- as.numeric(model.4.i.pop$model$past.conference.number.noIR)
conference.dummy <- ifelse(conference>0,1,0)
first.leader <- as.numeric(model.4.i.pop$model$first.leader)
plot.data <- data.frame(outcome,fitted,countryNames,conference,conference.dummy,first.leader)

plot.data <- plot.data %>%
				group_by(countryNames) %>%
					mutate(max.conference=max(conference))


p <- ggplot(data = plot.data, aes(x = outcome, y = fitted, color=conference)) +
        geom_point(position="jitter",alpha=0.5) +
        scale_color_gradient(name= "Conferences",low="lightgrey", high="darkblue") +
        geom_smooth(method = "lm", se = FALSE, col = "grey") +
        labs(title = "",
             x = "Observed",
             y = "Predicted")+ theme_bw() 

setwd(pathOUT)
ggsave("Pop_line.pdf",p,width = 10*1.63, height = 10, units = c("cm"))




####
fitted <- as.numeric(model.4.i.p$model[[1]] - model.4.i.p$residuals) 
countryNames <- epr.final$countryname[as.numeric(rownames(model.4.i.p$model))]
outcome <- as.numeric(model.4.i.p$model$inclprop)
conference <- as.numeric(model.4.i.p$model$past.conference.number.noIR)
conference.dummy <- ifelse(conference>0,1,0)

plot.data <- data.frame(outcome,fitted,countryNames,conference,conference.dummy)

plot.data <- plot.data %>%
				group_by(countryNames) %>%
					mutate(max.conference=max(conference))


p <- ggplot(data = plot.data, aes(x = outcome, y = fitted, color=conference)) +
        geom_point(position="jitter",alpha=0.5) +
        scale_color_gradient(name="Conferences",low="lightgrey", high="darkblue") +
        geom_smooth(method = "lm", se = FALSE, col = "grey") +
        labs(title = "",
             x = "Observed",
             y = "Predicted")+ theme_bw() 

setwd(pathOUT)
ggsave("P_line.pdf",p,width = 10*1.63, height = 10, units = c("cm"))

